<!-- 动态树形菜单页面 -->
<template>
  <div class="common_screen">

    <!-- 布局容器 -->
    <el-container :style="containerStyle">

      <!-- 左边导航栏 -->
      <el-aside width="200px" style="background-color:#545c64;">

        <el-menu
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
          :default-active="'index'"> <!-- router属性：表示使用router自由切换 -->
          <!-- 动态配置菜单-->
          <template v-for="item in menuList">
            <!-- 是否父级权限判断 -->
            <el-submenu :index=item.index v-if="!item.isContent">
              <template slot="title">
                <i :class=item.icon></i>
                {{item.name}}
              </template>
              <tree_menu v-bind:menuData=item.children></tree_menu>
            </el-submenu>

            <el-menu-item :index=item.index v-else>
              <i :class=item.icon></i>
              <span slot="title">{{item.name}}</span>
            </el-menu-item>

          </template>

        </el-menu>
      </el-aside>

      <!-- 右边主界面 -->
      <el-main>
        <router-view/>
      </el-main>


    </el-container>

  </div>
</template>


<script>

  //使用import导入tree_menu子组件
  import tree_menu from '@/components/common/tree_menu.vue'

  export default {
    //数据类型
    data () {
      return {
        //布局容器css样式配置
        containerStyle: {
          height: '100%',
          width: '100%'
        },
        //菜单动态数据
        menuList: [
          {
            name: '系统首页',
            index: '/index',
            icon: 'el-icon-location',
            isContent: true
          },
          {
            name: '系统管理',
            index: 'system',
            icon: 'el-icon-setting',
            isContent: false,
            children: [
              {
                name: '用户管理',
                index: '/system/userList'
              }, {
                name: '角色管理',
                index: '/system/roleList'
              }, {
                name: '权限管理',
                index: '/system/rightList'
              }
            ]
          },
          {
            name: '日志管理',
            index: 'log',
            icon: 'el-icon-view',
            isContent: false,
            children: [
              {
                name: '登陆日志',
                index: '/log/login'
              }, {
                name: '系统日志',
                index: '/log/system'
              }, {
                name: '日志监控',
                index: '/log/newest'
              }
            ]
          }
        ]
      }
    },
    //在components中引入子组件
    components: {
      tree_menu: tree_menu
    },
    //初始化加载
    mounted: function () {

    },
    //具体js方法
    methods: {
      handleOpen (key, keyPath) {
        console.log(key, keyPath)
      },
      handleClose (key, keyPath) {
        console.log(key, keyPath)
      }
    }
  }
</script>


<style scoped>


</style>
